using System.Drawing;
using System.Windows.Forms;

namespace ErkerTech.DeltaScope.View.Common
{
    public class ProgressStatusBar : StatusBar
    {
        public ProgressStatusBar()
        {
            SizingGrip = false;
            ShowPanels = true;
        }
        	
        protected override void OnDrawItem(StatusBarDrawItemEventArgs e)
        {
            if (e.Panel.GetType().ToString().EndsWith("ProgressPanel")) 
            {
                var ProgressPanel = (ProgressPanel) e.Panel;

                if (ProgressPanel.Value > ProgressPanel.Minimum)
                {
                    var NewWidth = (int)((ProgressPanel.Value / (double)ProgressPanel.Maximum) * ProgressPanel.Width);
                    var NewBounds = e.Bounds;
                    var PaintBrush = new SolidBrush(ProgressPanel.ForeColor);
                    NewBounds.Width = NewWidth;
	
                    e.Graphics.FillRegion(PaintBrush, new Region(NewBounds));
                    PaintBrush.Dispose();
                }
                else
                    base.OnDrawItem(e);
            }
            else
                base.OnDrawItem(e);
        }

        public void UpdateValue(ProgressPanel ProgressPanel, int NewValue)
        {
            ProgressPanel.Value = NewValue;
        }
    }

    public class ProgressPanel : StatusBarPanel
    {
        public ProgressPanel()
        {
            Style = StatusBarPanelStyle.OwnerDraw;
            ForeColor = Color.DarkBlue;
            Maximum = 100;
            Minimum = 1;
        }

        public int Minimum { get; set; }
        public int Maximum { get; set; }
        public int Value { get; set; }
        public Color ForeColor { get; set; }
    }
}